/*
 * Copyright 2011-2012 Redia A/S
 * 
 * This file is part of Redias Library App for Android.
 *
 *  Redia Library App for Android is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Redia Library App for Android is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with Redia Library App for Android.  If not, see <http://www.gnu.org/licenses/>.
 */
package dk.redia.libraryapp;

import android.content.Context;
import android.content.Intent;
import android.view.MenuItem;
import dk.redia.lib.log.Log;

public class GlobalMenuHandler {
	private static final String logTag = "GlobalMenuHandler";

	public static boolean onOptionsItemSelected(Context context, MenuItem item) {
		Intent intent;
		if (item.getItemId()==R.id.menuItemNews) {
			intent = new Intent(context, FrontPageActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			// Reenable to reuse existing activity
			//			intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
			context.startActivity(intent);	
		} else if (item.getItemId()== R.id.menuItemOpeningHours) {
			intent = new Intent(context, OpeningHoursLibraryListActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			context.startActivity(intent);
		} else if (item.getItemId()==R.id.menuItemItHappens) {
			intent = new Intent(context, ItHappensActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			context.startActivity(intent);
		} else if (item.getItemId()==R.id.menuItemMyLoans) {
			intent = new Intent(context, AuthenticateActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			intent.putExtra(AuthenticateActivity.EXTRAS_KEY_CALLBACK_CLASS, MyLoansActivity.class);
			context.startActivity(intent);
		} else if (item.getItemId()==R.id.menuItemReservationList) {
			intent = new Intent(context, AuthenticateActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			intent.putExtra(AuthenticateActivity.EXTRAS_KEY_CALLBACK_CLASS, MyReservationsActivity.class);
			context.startActivity(intent);
		} else {
			Log.e(logTag, "Unknown menu item clicked");
			return false;
		}
		
		/*
		switch (item.getItemId()) {
		case R.id.menuItemNews:
			intent = new Intent(context, FrontPageActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			// Reenable to reuse existing activity
			//			intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
			context.startActivity(intent);
			break;
		case R.id.menuItemOpeningHours:
			intent = new Intent(context, OpeningHoursLibraryListActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			context.startActivity(intent);
			break;
		case R.id.menuItemItHappens:
			intent = new Intent(context, ItHappensActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			context.startActivity(intent);
			break;
		case R.id.menuItemMyLoans:
			intent = new Intent(context, AuthenticateActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			intent.putExtra(AuthenticateActivity.EXTRAS_KEY_CALLBACK_CLASS, MyLoansActivity.class);
			context.startActivity(intent);
			break;
		case R.id.menuItemReservationList:
			intent = new Intent(context, AuthenticateActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			intent.putExtra(AuthenticateActivity.EXTRAS_KEY_CALLBACK_CLASS, MyReservationsActivity.class);
			context.startActivity(intent);
			break;
		default:
			Log.e(logTag, "Unknown menu item clicked");
			return false;
		}
		*/
		

		return true;
	}
}
